<?php
function webform_detail_DE($node,&$submission) {
  //-----------------------Special 'upload file' add by Tanky-------------------------------------------------------
  $is_approver_cid = 40;
  $attach_approval_cid = 43;
  if (isset($submission->data[$is_approver_cid]['value'][0]) && $submission->data[$is_approver_cid]['value'][0] == 1) {
    if (isset($submission->data[$attach_approval_cid]['value'][0])) {
      $fid = $submission->data[$attach_approval_cid]['value'][0]; //echo $fid;exit;
      if ($fid > 0) {
        db_delete('webform_submitted_data')
                ->condition('sid', $submission->sid)
                ->condition('cid', $attach_approval_cid)
                ->execute();

        $sql = "update {file_managed} set status=0 where fid=" . $fid;
        db_query($sql);
      }
    }
  }
}

function webform_detail_label_translation($node){
  global $language;
  $lang_wf = (isset($language->language)) ? $language->language : WEBFORM_DEFAULT_LANGUAGE;
  if ($lang_wf != WEBFORM_DEFAULT_LANGUAGE) {
    $lang = _get_webform_translation();
    $lid = isset($lang['lid'][$lang_wf]) ? $lang['lid'][$lang_wf] : 0;
    $translations = _get_webform_component_translation($node->nid, $lid); //print_r($translations);exit;
    //print_r($node->webform['components']);exit;
    if (isset($node->webform['components'])) {
      foreach ($node->webform['components'] as $cid => $component) {
        // For label title
        $node->webform['components'][$cid]['name_en'] = $node->webform['components'][$cid]['name'];
        if (!empty($translations[$cid]->name)) {
          $node->webform['components'][$cid]['name'] = $translations[$cid]->name;
        }

        // For Select(customer and pre build list) translation
        if ($node->webform['components'][$cid]['type'] == 'select') {
          $options_info = _webform_select_options_info();
          $source_name = $node->webform['components'][$cid]['extra']['options_source'];
          if ($source_name && isset($options_info[$source_name])) {
            $node->webform['components'][$cid]['extra']['lang_wf'] = $lang_wf;
          } else {
            $node->webform['components'][$cid]['extra']['items_en'] = $node->webform['components'][$cid]['extra']['items'];
            if (!empty($translations[$cid]->items)) {
              $node->webform['components'][$cid]['extra']['items'] = $translations[$cid]->items;
            }
          }
        }

        // For Markup with 'value' translation, others with 'description' translation
        if ($node->webform['components'][$cid]['type'] == 'markup') {
          $node->webform['components'][$cid]['value_en'] = $node->webform['components'][$cid]['value'];
          if (!empty($translations[$cid]->value)) {
            $node->webform['components'][$cid]['value'] = $translations[$cid]->value;
          }
        } else {
          $node->webform['components'][$cid]['extra']['description_en'] = $node->webform['components'][$cid]['extra']['description'];
          if (!empty($translations[$cid]->description)) {
            $node->webform['components'][$cid]['extra']['description'] = $translations[$cid]->description;
          }
        }
      }
    }
  }
}